/***************************************************************************************
 *
 *  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
 *
 *  By downloading, copying, installing or using the software you agree to this license.
 *  If you do not agree to this license, do not download, install, 
 *  copy or use the software.
 *
 *  Copyright (C) 2014-2019, Happytimesoft Corporation, all rights reserved.
 *
 *  Redistribution and use in binary forms, with or without modification, are permitted.
 *
 *  Unless required by applicable law or agreed to in writing, software distributed 
 *  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 *  language governing permissions and limitations under the License.
 *
****************************************************************************************/

#ifndef	SYS_BUF_H
#define	SYS_BUF_H

/***************************************************************************************/
#define MAX_AVN				8	
#define MAX_AVDESCLEN		500	
#define MAX_USRL			64	
#define MAX_PWDL			32	
#define MAX_NUML			64
#define MAX_UA_ALT_NUM		8


#include "sys_inc.h"
#include "../defineconfig.h"
/***************************************************************************************/
typedef struct header_value
{
	char	header[32];
	char *	value_string;
} HDRV;

typedef struct ua_address_info
{
	uint32	ip;
	uint16	port;
	uint16	type;	                // UDP - 0; TCP-PASSIVE - 1; TCP-ACTIVE - 2
	char    user[64];
	char    passwd[64];
} UA_ADDRINFO;

typedef struct ua_media_session_info
{
	int     ua_m_fd;
	int     ua_m_fd_talk;//上行连接 fd
	uint32	conn_addr;				//一般应该=0，某些SDP里面在m=audio/video后面还有这个
	uint16	remote_port;			//对应ua宣称的媒体端口
	uint16	local_port;				//媒体代理时服务器对该用户分配的端口
	uint32	local_ip;				//自己的IP地址，可能不是本机

    uint32	mux_id;					// 端口复用ID，如果=0为无效
    int     mux_fd;                 // 复用接收/发送socket文件
    
	uint32	rx_pkt_cnt;				//统计收到的媒体包个数
	uint32	tx_pkt_cnt;

	uint32	last_pkt_time;	
} UA_MEDIA;

typedef struct ua_rtp_info
{
	int     rtp_cnt;				
	uint32	rtp_ssrc;				
	uint32	rtp_ts;					
	uint8	rtp_pt;					
} UA_RTP_INFO;

typedef struct
{
    /* rtcp sender statistics */
    
    int64   last_rtcp_ntp_time;
    int64   first_rtcp_ntp_time;
    uint32  packet_count;
    uint32  octet_count;
    uint32  last_octet_count;
    int     first_packet;
    char    cname[64];
} UA_RTCP_INFO;

typedef struct http_digest_auth_info
{
	char    auth_name[MAX_USRL];
	char    auth_pwd[64];
	char    auth_uri[256];			
	char    auth_qop[32];
	char    auth_nonce[128];
	char    auth_cnonce[128];
	char    auth_realm[128];
	char    auth_opaque[128];
	int     auth_nc;
	char    auth_ncstr[12];
	char    auth_response[36];
} HD_AUTH_INFO;

#ifdef __cplusplus
extern "C" {
#endif

extern PPSN_CTX * hdrv_buf_fl;

/***********************************************************************/
BOOL    net_buf_init(int num, int size);
void    net_buf_deinit();

char  * net_buf_get_idle();
void    net_buf_free(char * rbuf);
uint32  net_buf_get_size();
uint32  net_buf_idle_num();

/***********************************************************************/
BOOL    hdrv_buf_init(int num);
void    hdrv_buf_deinit();

HDRV  * hdrv_buf_get_idle();
void    hdrv_buf_free(HDRV * pHdrv);
uint32  hdrv_buf_idle_num();

void    hdrv_ctx_ul_init(PPSN_CTX * ul_ctx);
void    hdrv_ctx_free(PPSN_CTX * p_ctx);

/***********************************************************************/
BOOL    sys_buf_init(int nums);
void    sys_buf_deinit();
/***********************************************************************/


#ifdef __cplusplus
}
#endif

#endif	// SYS_BUF_H



